package timbap.visualizer.coreplugins.lib.artworkhue;

import timbap.visualizer.api.model.PlaylistEntry;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class PlaylistEntryByHueComparator implements Comparator<PlaylistEntry> {

    private Map<PlaylistEntry, HueComparableColor> playlistEntryHueMap =
            new HashMap<PlaylistEntry, HueComparableColor>();

    public PlaylistEntryByHueComparator(Map<PlaylistEntry, HueComparableColor> pPlaylistEntryHueMap) {
        playlistEntryHueMap = pPlaylistEntryHueMap;
    }

    public Map<PlaylistEntry, HueComparableColor> getPlaylistEntryHueMap() {
        return playlistEntryHueMap;
    }

    public void setPlaylistEntryHueMap(Map<PlaylistEntry, HueComparableColor> pPlaylistEntryHueMap) {
        playlistEntryHueMap = pPlaylistEntryHueMap;
    }

    public int compare(PlaylistEntry pO1, PlaylistEntry pO2) {
        HueComparableColor o1Hue = playlistEntryHueMap.get(pO1);
        HueComparableColor o2Hue = playlistEntryHueMap.get(pO2);
        if (o1Hue != null && o2Hue != null) {
            return o1Hue.compareTo(o2Hue);
        } else {
            if (o1Hue == null && o2Hue != null) {
                return 1;
            } else if (o1Hue != null) {
                return -1;
            }
        }
        return 0;
    }

}